package com.shuoyue.ycgk.ui.papergroups.running.myrush;

import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpFragment;
import com.shuoyue.ycgk.entity.Paper;
import com.shuoyue.ycgk.entity.UserTestPaper;
import com.shuoyue.ycgk.ui.papergroups.CreatePagerSetContract;
import com.shuoyue.ycgk.ui.papergroups.adapter.PaperAdapter;
import com.shuoyue.ycgk.ui.questionbank.practice.paperset.questionitem.DoPaperActivity;

import java.util.ArrayList;

import butterknife.BindView;

public class FragmentUserRush extends BaseMvpFragment implements CreatePagerSetContract.View {
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    String title = "";
    ArrayList<Paper> papers;

    PaperAdapter paperAdapter;
    protected CreatePagerSetContract.Presenter createPresenter;

    @Override
    public void initParams(Bundle bundle) {
        papers = (ArrayList<Paper>) bundle.getSerializable("data");
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_only_list;
    }

    @Override
    protected void initView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        paperAdapter = new PaperAdapter(papers);
        recyclerView.setAdapter(paperAdapter);
        paperAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            Paper paper = (Paper) adapter.getItem(position);
            createPaper(paper);
        });
    }

    @Override
    protected void initData() {
        super.initData();
        createPresenter = new CreatePagerSetContract.Presenter();
        createPresenter.attachView(this);
    }

    public static FragmentUserRush getInstance(String modelName, ArrayList<Paper> papers) {
        FragmentUserRush fragment = new FragmentUserRush();
        fragment.title = modelName;
        Bundle bundle = new Bundle();
        bundle.putSerializable("data", papers);
        fragment.setArguments(bundle);
        return fragment;
    }

    void createPaper(Paper paper) {
        createPresenter.createSetPaper(paper.getId(), paper.getName());
    }

    @Override
    public void createPaperSuc(UserTestPaper userTestPaper) {
        DoPaperActivity.start(mContext, userTestPaper);
    }

    @Override
    public String getTitle() {
        return title;
    }
}
